function point = threeball(x1,y1,z1,r1,x2,y2,z2,r2,x3,y3,z3,r3)
%求解三球交点
A1=r1^2-x1^2-y1^2-z1^2;
A2=r2^2-x2^2-y2^2-z2^2;
A3=r3^2-x3^2-y3^2-z3^2;
A21=-(A2-A1)/2;
A31=-(A3-A1)/2;

X21=x2-x1;
X31=x3-x1;
Y21=y2-y1;
Y31=y3-y1;
Z21=z2-z1;
Z31=z3-z1;
D=X21*Y31-Y21*X31;

B0=(A21*Y31-A31*Y21)/D;
B1=(Y21*Z31-Y31*Z21)/D;
C0=(A31*X21-A21*X31)/D;
C1=(X31*Z21-X21*Z31)/D;

E=B1^2+C1^2+1;
F=B1*(B0-x1)+C1*(C0-y1)-z1;
G=(B0-x1)^2+(C0-y1)^2+z1^2-r1^2;

point(3)=(-F+(F^2-E*G)^(1/2))/E;
point(1)=B0+B1*point(3);
point(2)=C0+C1*point(3);
end

